#include<bits/stdc++.h>
using namespace std;

int a[100005], b[100005], c[100005];
int f[100005];

int main()
{
	int n;
	cin>>n;
	unordered_map<int, int> mp;
	for(int i = 1;i <= n;i++)
	{
		cin>>a[i];
		mp[a[i]] = i;
	}
	for(int i = 1;i <= n;i++)
	{
		cin>>b[i];
		c[i] = mp[b[i]];
	}
	for(int i = 1;i <= n;i++)
	{
		if(c[i] >= c[i-1])
			f[i] = f[i-1]+1;
		else
			f[i] = f[i-1];
	}
	cout<<f[n];
	return 0;
}

